// pages/index/goods/mulu-cont/mulu-cont.js
const app = getApp()
import { request } from '../../../../utils/api'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 自定义nav
    statusBarHeight1: app.globalData.statusBarHeight+45,
    // 页面数据
    data: {},
    imgBaseUrl: app.globalData.imgBaseUrl,
    // 当前目录Id
    mlId: '',
    bookId: '',
    pId: '',
    // 考点那些 显示开关
    showMore: false
  },
  // 返回
  goBack() {
    wx.navigateBack({
      delta: 1
    })
  },
  // 切换兰改变事件
  onTabChange(e) {
    console.log(e);
    let title = e.detail.title 
    if(title == '考点视频分析') {
      this.setData({
        showMore: true
      })
    } else {
      this.setData({
        showMore: false
      })
    }
  },
  // 获取目录详情
  getMuLuDetail(pid,id, bookId) {
    request({
      url: '/zhongyisheji-applet/lookBook/private/getbookPlanDetils',
      method: 'post',
      data: {
        catalogId: id,
        bookId,
        parentCatalogId: pid
      }
    }).then(res => {
      console.log(res);
      if(res.code == 200) {
        // let regex = new RegExp('<img', 'gi');
        // res.data.bookCatalogContent.catalogContent = res.data.bookCatalogContent.catalogContent.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.guifanshuoming = res.data.bookCatalogContent.guifanshuoming.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.guifanlijie = res.data.bookCatalogContent.guifanlijie.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.shejiyunyong = res.data.bookCatalogContent.shejiyunyong.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.linianzhenti = res.data.bookCatalogContent.linianzhenti.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.kaodianfenxi = res.data.bookCatalogContent.kaodianfenxi.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.kaodianguina = res.data.bookCatalogContent.kaodianguina.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.juyifansan = res.data.bookCatalogContent.juyifansan.replace(regex, `<img style="width: 100%;"`);
        // res.data.bookCatalogContent.kaodianlianxi = res.data.bookCatalogContent.kaodianlianxi.replace(regex, `<img style="width: 100%;"`);
        this.setData({
          data: res.data
        })
      }
    })
  },
  // 上一页
  onPrev() {
    console.log('prec');
    this.getDiffData(1)
  },
  // 下一页
  onNext() {
    console.log('next');
    this.getDiffData(2)
  },
  aaaa() {
    console.log('231');
  },
  getDiffData(type) {
    request({
      url: '/zhongyisheji-applet/lookBook/private/changeCatalogContent',
      method: 'post',
      data: {
        catalogId: this.data.mlId,
        bookId: this.data.bookId,
        parentCatalogId: this.data.pId,
        type
      }
    }).then(res => {
      console.log(res);
      if(res.code == 200) {
        let regex = new RegExp('<img', 'gi');
        res.data.bookCatalogContent.catalogContent = res.data.bookCatalogContent.catalogContent.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.guifanshuoming = res.data.bookCatalogContent.guifanshuoming.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.guifanlijie = res.data.bookCatalogContent.guifanlijie.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.shejiyunyong = res.data.bookCatalogContent.shejiyunyong.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.linianzhenti = res.data.bookCatalogContent.linianzhenti.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.kaodianfenxi = res.data.bookCatalogContent.kaodianfenxi.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.kaodianguina = res.data.bookCatalogContent.kaodianguina.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.juyifansan = res.data.bookCatalogContent.juyifansan.replace(regex, `<img style="width: 100%;"`);
        res.data.bookCatalogContent.kaodianlianxi = res.data.bookCatalogContent.kaodianlianxi.replace(regex, `<img style="width: 100%;"`);
        this.setData({
          data: res.data,
          pId: res.data.parentCatalogId,
          mlId: res.data.catalogId
        })
      } else {
        wx.showToast({
          title: res.msg,
          icon: 'none'
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let id = options.id
    console.log(options);
    this.getMuLuDetail(options.pId, id, options.bookId)
    this.setData({
      mlId: id,
      bookId: options.bookId,
      pId: options.pId
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  // onShareAppMessage: function () {

  // }
})